<template>
  <el-row type="flex" style="width:100%">
    <el-col>{{ tree.name }}</el-col>
    <el-col :span="4">
      <el-row type="flex">
        <el-col>{{ tree.manager }}</el-col>
        <el-col>
          <el-dropdown>
            <span class="el-dropdown-link">
              操作
              <i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="add">添加</el-dropdown-item>
              <template v-if="!isRoot">
                <el-dropdown-item @click.native="editDep">编辑</el-dropdown-item>
                <el-dropdown-item @click.native="delDep">删除</el-dropdown-item>
              </template>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepts } from '@/api/department'
export default {
  name: 'TreeTools',
  props: {
    tree: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      required: false
    }
  },
  methods: {
    delDep() {
      this.$confirm('确认关闭？')
        .then(() => {
          return delDepts(this.tree.id)
        }).then(() => {
          // 删除成功执行这里
          this.$message.success('删除成功')
          // 通知父组件改数据
          this.$emit('delDeps')
        })
    },
    add() {
      this.$emit('addDep', this.tree)
    },
    editDep() {
      this.$emit('deitDep', this.tree)
    }
  }
}
</script>

<style>

</style>
